package cc.eddic.pratice.programmingparadigms.exam.impl;

import cc.eddic.pratice.programmingparadigms.exam.Model.AnswerModel;
import cc.eddic.pratice.programmingparadigms.exam.QuestionBankService;
import cc.eddic.pratice.programmingparadigms.exam.QuestionType;
import cc.eddic.pratice.programmingparadigms.exam.domain.Option;
import cc.eddic.pratice.programmingparadigms.exam.domain.Question;
import java.util.ArrayList;
import java.util.List;

public class QuestionBankServiceLh2Impl extends   QuestionBankServiceImpl implements QuestionBankService {

    @Override
    public List<Question> importQuestions(String questionTextFile) {
        String file=getQuestionFileContent();
        String[] fileList=new String[160];
        for(int i=0,n=0,j=0;i<file.length();i++){
            if (file.charAt(i) == '\n'){
                fileList[n]=file.substring(j,i);
                n++;
                j=i+1;
            }
        }
        List<Question> questionList=new ArrayList<>();
        for (int i=0,n=1;i<fileList.length;i++){
            if (fileList[i]==null) break;
            if (i%6==0){
                Question q1=new Question(n,fileList[i].substring(fileList[i].indexOf("、")+1), QuestionType.SINGLE_CHOICE);
                for (int j=0;j<4;j++){
                    i++;
                    q1.add(new Option(fileList[i].substring(2),fileList[i].charAt(0),false));
                }
                questionList.add(q1);
                n++;
            }
        }
        return questionList;
    }

    @Override
    public List<Question> importCorrectAnswers(String correctAnswerTextFile) {

        return null;
    }

    @Override
    public List<AnswerModel> readCorrectAnswers(String correctAnswerTextFile) {
        return null;
    }

    @Override
    public List<Question> importCategories(String categoryExcelFile) {
        return null;
    }
}
